﻿
namespace TTprotons.Crm.JavascriptAudit.Common
{
    public class JavascriptEvent
    {
        public string EntityName
        { get; set; }

        public string EventName
        { get; set; }

        public string FieldName
        { get; set; }

        public string FieldLogicalName
        { get; set; }

        public FormTypes FormType
        { get; set; }

        public bool IsActive
        { get; set; }

        public JavascriptTypes JavascriptType
        { get; set; }

        public string JavascriptCode
        { get; set; }

        public override bool Equals(object obj)
        {
            var other = obj as JavascriptEvent;
            if (other == null) return false;

            var isEqual = other.EntityName.Equals(EntityName) && other.FormType.Equals(FormType) &&
                          other.JavascriptType.Equals(JavascriptType) && other.EventName.Equals(EventName);

            if (other.FieldLogicalName == null && FieldLogicalName == null)
                return isEqual;
            
            if (other.FieldLogicalName == null || FieldLogicalName == null)
                return !isEqual;

            return isEqual && other.FieldLogicalName.Equals(FieldLogicalName);
        }
    }
}